package com.pushdemo.logic;

import android.content.Context;
import android.util.Log;
import com.pushdemo.config.ChameleonConstants;
//import com.foreveross.httputil.HttpRequestAsynTask;
//import com.foreveross.httputil.HttpUtil;
/**
 * Created by zhouzhineng on 14-8-20.
 */
public class ChameleonAuthDelegate{

/*    public final static String TAG = "ChameleonAuthDelegate";
    private Context mContext;
    private AuthCallback callback;

    public interface AuthCallback{
        public void requestStart();
        public void requestSuccess(String json);
        public void requestFailed(String msg);
    }

    public ChameleonAuthDelegate(Context context) {
        mContext = context;
    }

    //@Override
    public void auth(AuthCallback callback) {
        this.callback = callback;
        HttpRequestAsynTask loginTask = doHttp(mContext,callback);
        loginTask.setDialogContent("正在验证...");
        loginTask.setLockScreen(true);
        loginTask.setShowProgressDialog(true);
        loginTask.setNeedProgressDialog(true);
        StringBuilder sb = new StringBuilder();
        String appKey = ChameleonConstants.APPKEY;
        String secret = ChameleonConstants.SECRET;
        sb = sb.append("Form:appKey=").append(appKey).append(";secret=").append(secret);
        String s = sb.toString();
        String url = ChameleonConstants.AUTH;
        loginTask.execute(url, s, HttpUtil.UTF8_ENCODING, HttpUtil.HTTP_POST);
    }

    private HttpRequestAsynTask doHttp(Context context,final AuthCallback callback){
        HttpRequestAsynTask task = new HttpRequestAsynTask(context){
            @Override
            public void doPreExecuteBeforeDialogShow() {

                super.doPreExecuteBeforeDialogShow();
                callback.requestStart();
            }

            @Override
            public void doPreExecuteWithoutDialog() {

                super.doPreExecuteWithoutDialog();
                callback.requestStart();
            }

            @Override
            protected void doPostExecute(String result) {

                super.doPostExecute(result);
                callback.requestSuccess(result);
            }

            @Override
            protected void doHttpFail(Exception e) {

                super.doHttpFail(e);
                callback.requestFailed(e.getMessage());
            }
        };
        return task;
    }*/
}
